package
{
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	
	[SWF(width="800", height="600", frameRate="30", backgroundColor="0xff0000")]
	public class first extends MovieClip
	{
		public static const STATE_INIT:int = 10;
		public static const STATE_PLAY:int = 20;
		public static const STATE_GAME_OVER:int = 30;
		public var gameState:int = 0;
		public var click:int = 0;
		
		//This is our first program
		public function first()
		{
			addEventListener(Event.ENTER_FRAME, gameLoop);
			gameState = STATE_INIT;
		}
		
		public function gameLoop(e:Event):void{
			switch(gameState){
				case STATE_INIT:
					initGame();
					break;
				case STATE_PLAY:
					playGame();
					break;
				case STATE_GAME_OVER:
					gameOver();
					break;
			}
		}
		
		public function initGame():void{
			stage.addEventListener(MouseEvent.CLICK, onMouseClickEvent);
			click = 0;
			gameState = STATE_PLAY;
		}
		
		public function onMouseClickEvent(e:MouseEvent):void{
			++click;
			trace("mouse click:" + click);
		}
		
		public function playGame():void{
			if(click >= 10) gameState = STATE_GAME_OVER;
		}
		
		public function gameOver():void{
			stage.removeEventListener(MouseEvent.CLICK, onMouseClickEvent);
			gameState = STATE_INIT;
			trace("Game Over");
		}
	}
}